/** FASSIT (Forms of Selective Attention in Intelligent Transportation Systems)
 * Computational Creativity and Digital Media
 * Cognitive and Media Systems Group
 * Centre for Informatics and Systems of the University of Coimbra (CISUC)
 *
 * Copyright (c) 2010-2013 University of Coimbra, Portugal
 * All rights reserved.
 */

package poi.UncertaintyCalculator;

import java.util.ArrayList;
import java.util.HashMap;

import poi.Info.DaysOff;
import poi.Info.POI;
import poi.Uncertainty.*;
import functionsVariables.Constants;

/**
 * This class is used to calculate the Master agent Uncertainty for the
 * parameter DayOff
 * 
 * @author Hernani Costa
 * @version 0.1 date: 27/01/2013
 */
public class UncertaintyCalculatorForDaysOff {
	HashMap<Integer, UncertaintyDaysOff> poiUncertaintyDayOff;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 * 
	 * @param pois
	 *            - list with the POIs that we intend to calculate the
	 *            Uncertainty
	 */
	public UncertaintyCalculatorForDaysOff(HashMap<Integer, POI> pois) {
		poiUncertaintyDayOff = new HashMap<Integer, UncertaintyDaysOff>();
		calculates_Surprise_Knowledge_About_DayOff(pois);
	}

	/**
	 * Calculates the Uncertainty for the parameter DayOff
	 * 
	 * @param pois
	 *            - list with the POIs that we intend to calculate the
	 *            Uncertainty
	 */
	private void calculates_Surprise_Knowledge_About_DayOff(
			HashMap<Integer, POI> pois) {
		UncertaintyDaysOff uncertaintyDayOff = null;
		double val = 0.0;
		for (POI poi : pois.values()) {

			DaysOff dayOff = poi.getDaysOff();
			if (!dayOff.hasDaysOff()) {
				val = 1.0 / 7.0;
				uncertaintyDayOff = new UncertaintyDaysOff(val, val, val, val,
						val, val, val);
			} else {
				ArrayList<String> listOfDaysOff = dayOff.getListDaysOff();
				double divisor = listOfDaysOff.size();
				int[] intDayOff = Constants.getIntFromStrDays(listOfDaysOff);

				uncertaintyDayOff = new UncertaintyDaysOff(intDayOff[0]
						* (1.0 / divisor), intDayOff[1] * (1.0 / divisor),
						intDayOff[2] * (1.0 / divisor), intDayOff[3]
								* (1.0 / divisor), intDayOff[4]
								* (1.0 / divisor), intDayOff[5]
								* (1.0 / divisor), intDayOff[6]
								* (1.0 / divisor));
			}

			poiUncertaintyDayOff.put(poi.getPoiID(), uncertaintyDayOff);
		}
	}

	// ------------------------------------------------------------------------
	// ------------------------GETs and SETs-----------------------------------
	// ------------------------------------------------------------------------

	public HashMap<Integer, UncertaintyDaysOff> getPoiUncertaintyDayOff() {
		return poiUncertaintyDayOff;
	}

	/**
	 * 
	 * @return a String with the Surprise values for the parameter Schedule, for
	 *         all POIs
	 */
	public String to_String() {
		String info = "";
		for (int poiID : poiUncertaintyDayOff.keySet()) {
			info += "poiID: " + poiID + "\n\t"
					+ poiUncertaintyDayOff.get(poiID).to_String() + "\n";
		}
		return info;
	}

}
